package net.pimpas.web.jsf.components.ajax.populate.autoupdate;

import javax.faces.context.FacesContext;

import net.pimpas.web.jsf.components.ajax.populate.UIAjaxPopulate;

public class UIAjaxPopulateAutoUpdate extends UIAjaxPopulate {
	
	public static final String COMPONENT_TYPE			= UIAjaxPopulate.COMPONENT_TYPE+".autoupdate";
	public static final String COMPONENT_FAMILY			= UIAjaxPopulate.COMPONENT_FAMILY+".autoupdate";
	public static final String COMPONENT_RENDER_TYPE	= UIAjaxPopulate.COMPONENT_RENDER_TYPE+".autoupdate";
	
	public static final Integer DEFAULT_TIMER			= 1000;
	
	private Integer timer;
	
	@Override
	public Object saveState(FacesContext context) {
		Object[] ob = new Object[2];
		ob[0] = super.saveState(context);
		ob[1] = this.getTimer();
		
		return ob;
	}
	
	@Override
	public void restoreState(FacesContext context, Object state) {
		Object[] ob = (Object[]) state;
		super.restoreState(context, ob[0]);
		this.setTimer((Integer) ob[1]);
	}

	@Override
	public String getRendererType() {
		return COMPONENT_RENDER_TYPE;
	}

	@Override
	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public Integer getTimer() {
		return timer;
	}

	public void setTimer(Integer timer) {
		this.timer = timer;
	}
}